package com.imooc.miaosha.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.imooc.miaosha.daomain.MiaoshaGoods;
import com.imooc.miaosha.vo.GoodsVo;

@Mapper
public interface GoodsDao {
	
	@Select("SELECT g.*,mg.stock_count,mg.miaosha_price,mg.start_date,mg.end_date from miaosha_goods mg LEFT JOIN goods g ON mg.id = g.id")
	public List<GoodsVo> listGoodsVo();
	
	@Select("SELECT g.*,mg.stock_count,mg.miaosha_price,mg.start_date,mg.end_date from miaosha_goods mg LEFT JOIN goods g ON mg.id = g.id where g.id=#{goodsId}")
	public GoodsVo getGoodsVoByGoodsId(long goodsId);
	
	@Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId} and stock_count > 0")
	public int reduceStock(MiaoshaGoods g);

}
